package com.lenovo.vod.player;

import com.lenovo.vod.player.R;
import com.lenovo.vod.player.Constant;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

public class ControllerFragment extends Fragment {
	private View mView;
	private TextView mTotalTimeView, mCurrTimeView, mCurrTimeViewLeftBottom;
	private TextView mTitleView;
	private ImageView mBackwardView, mForwardView, mPlayView;
	private SeekBar mSeekBar;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.d(Constant.TAG, "ControllerFragment onCreateView called");

		mView = inflater.inflate(R.layout.vodplayer_controller, container,
				false);
		hide();

		mSeekBar = (SeekBar) mView.findViewById(R.id.vodplayer_seek_bar);
		mTotalTimeView = (TextView) mView
				.findViewById(R.id.vodplayer_time_label_total);
		mCurrTimeView = (TextView) mView
				.findViewById(R.id.vodplayer_time_label_curr);
		mCurrTimeViewLeftBottom = (TextView) this.mView.findViewById(R.id.seekpos);
		mTitleView = (TextView) mView.findViewById(R.id.vodplayer_movie_title);
		mBackwardView = (ImageView) mView.findViewById(R.id.vodplayer_backward);
		mForwardView = (ImageView) mView.findViewById(R.id.vodplayer_forward);
		mPlayView = (ImageView) mView.findViewById(R.id.vodplayer_play);

		return mView;
	}

	public SeekBar getSeekBar() {
		return mSeekBar;
	}

	public void setDuration(int duration) {
		mSeekBar.setMax(duration);
	}

	public void setTotalTime(String text) {
		mTotalTimeView.setText(text);
	}

	public void setProgress(int progress) {
		mSeekBar.setProgress(progress);
	}

	public void setCurrTime(String text) 
	{
		mCurrTimeView.setText(text);
		mCurrTimeViewLeftBottom.setText(text);
	}

	public void show() {
		mView.setVisibility(View.VISIBLE);
	}

	public void hide() {
		mView.setVisibility(View.INVISIBLE);
	}

	public void setFastForward(boolean isForwarding) {
		if (isForwarding)
			mForwardView.setImageResource(R.drawable.vodplayer_forward_1);
		else
			mForwardView.setImageResource(R.drawable.vodplayer_forward);
	}

	public void setFastBackward(boolean isBackwarding) {
		if (isBackwarding)
			mBackwardView.setImageResource(R.drawable.vodplayer_backward_1);
		else
			mBackwardView.setImageResource(R.drawable.vodplayer_backward);
	}

	public void setTitle(String title) 
	{
		mTitleView.setText(title);
	}

	public void setPause(boolean pause) {
		if (pause)
			mPlayView.setImageResource(R.drawable.vodplayer_play_1);
		else
			mPlayView.setImageResource(R.drawable.vodplayer_play);
	}
}
